<?php 
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
	session_start(); 
}

if(isset($_SESSION['lang']))
$lang=$_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
	include "../../value/value_en.php";
} else if($lang == "VN") {
	include "../../value/value_vn.php";
}
else {
	include "../../value/value_kr.php";
}
include '../../operations/connection.php';
include '../../generallibraries/funcs.php';
$_SESSION['loi_allowance_hard_holiday']="";
if(isset($_REQUEST['hanhdong'])){
	if($_REQUEST['hanhdong']=='add'){
		$is_late=$_REQUEST['islate'];
		$is_half_dayoff=$_REQUEST['ishalfdayoff'];
		$allowance_holiday=generalFunctions::numberformat_to_basicString($_REQUEST['aholiday']);
		$is_all_dayoff=$_REQUEST['isalldayoff'];
		$allowance_hard=generalFunctions::numberformat_to_basicString($_REQUEST['ahard']);
		$is_status=$_REQUEST['astatus'];
		$sub_salary_day=$_REQUEST['subsalaryday'];
		
		$sql="SELECT sa_allowance_hard_holiday.id,sa_allowance_hard_holiday.is_status 
		from sa_allowance_hard_holiday 
		where sa_allowance_hard_holiday.allowance_hard=".$allowance_hard." and 
		sa_allowance_hard_holiday.allowance_holiday=".$allowance_holiday." and 
		sa_allowance_hard_holiday.is_all_dayoff=".$is_all_dayoff." and 
		sa_allowance_hard_holiday.is_half_dayoff=".$is_half_dayoff." and 
		sa_allowance_hard_holiday.is_late=".$is_late." and 
		sa_allowance_hard_holiday.sub_salary_day=".$sub_salary_day;
		$kq=mysql_query($sql);
		if(mysql_num_rows($kq)>0){
			$_SESSION['loi_allowance_hard_holiday']=$l_dulieu_daco;
		}else{
			$query="insert into sa_allowance_hard_holiday (is_late,is_all_dayoff,is_half_dayoff,allowance_hard,allowance_holiday,date_created,user_created,is_status,sub_salary_day) 
			values (".$is_late.",".$is_all_dayoff.",".$is_half_dayoff.",".$allowance_hard.",".$allowance_holiday.",now(),'".$_SESSION['IDEmployee']."',".$is_status.",".$sub_salary_day.")";
			mysql_query($query);
			$_SESSION['loi_allowance_hard_holiday']=$l_themthanhcong;
		}
	}else if($_REQUEST['hanhdong']=='update'){
		$iddel=$_REQUEST['idgen'];
		$is_late=$_REQUEST['islate'];
		$is_half_dayoff=$_REQUEST['ishalfdayoff'];
		$allowance_holiday=generalFunctions::numberformat_to_basicString($_REQUEST['aholiday']);
		$is_all_dayoff=$_REQUEST['isalldayoff'];
		$allowance_hard=generalFunctions::numberformat_to_basicString($_REQUEST['ahard']);
		$is_status=$_REQUEST['astatus'];
		$sub_salary_day=$_REQUEST['subsalaryday'];
		
		$sql1="SELECT sa_allowance_hard_holiday.id,sa_allowance_hard_holiday.is_status 
		from sa_allowance_hard_holiday 
		where sa_allowance_hard_holiday.allowance_hard=".$allowance_hard." and 
		sa_allowance_hard_holiday.allowance_holiday=".$allowance_holiday." and 
		sa_allowance_hard_holiday.is_all_dayoff=".$is_all_dayoff." and 
		sa_allowance_hard_holiday.is_half_dayoff=".$is_half_dayoff." and 
		sa_allowance_hard_holiday.is_late=".$is_late." and 
		sa_allowance_hard_holiday.sub_salary_day=".$sub_salary_day." and sa_allowance_hard_holiday.id !=".$iddel;

		$kq1=mysql_query($sql1);
		if(mysql_num_rows($kq1)>0){
			$_SESSION['loi_allowance_hard_holiday']=$l_dulieu_daco;
		}else{
			$sql="update sa_allowance_hard_holiday set 
			sa_allowance_hard_holiday.is_late=".$is_late.",
			sa_allowance_hard_holiday.is_all_dayoff=".$is_all_dayoff.",
			sa_allowance_hard_holiday.is_half_dayoff=".$is_half_dayoff.",
			sa_allowance_hard_holiday.allowance_hard=".$allowance_hard.",
			sa_allowance_hard_holiday.allowance_holiday=".$allowance_holiday.",
			sa_allowance_hard_holiday.user_last_update='".$_SESSION['IDEmployee']."',
			sa_allowance_hard_holiday.date_last_update=now(),
			sa_allowance_hard_holiday.is_status=".$is_status.",
			sa_allowance_hard_holiday.sub_salary_day=".$sub_salary_day." where sa_allowance_hard_holiday.id=".$iddel;
			mysql_query($sql);
			$_SESSION['loi_allowance_hard_holiday']=$l_capnhatthanhcong;
		}
		
	}else if($_REQUEST['hanhdong']=='del'){
		$iddel=$_REQUEST['idgen'];
		$sql="SELECT sa_allowance_hard_holiday.id,sa_allowance_hard_holiday.is_status from sa_allowance_hard_holiday where sa_allowance_hard_holiday.is_status=1 and sa_allowance_hard_holiday.id=".$iddel;
		$kq=mysql_query($sql);
		if(mysql_num_rows($kq)>0){
			$_SESSION['loi_allowance_hard_holiday']=$l_dang_active_khongxoa;
		}else{
			$query="DELETE from sa_allowance_hard_holiday where sa_allowance_hard_holiday.id=".$iddel." and sa_allowance_hard_holiday.is_status=0";
			$kq=mysql_query($query);
			$_SESSION['loi_allowance_hard_holiday']=$l_xoathanhcong;
		}
	}
}
$query="select sa_allowance_hard_holiday.sub_salary_day,sa_allowance_hard_holiday.id,sa_allowance_hard_holiday.allowance_hard,sa_allowance_hard_holiday.allowance_holiday,sa_allowance_hard_holiday.is_all_dayoff,sa_allowance_hard_holiday.is_half_dayoff,sa_allowance_hard_holiday.is_late,sa_allowance_hard_holiday.is_status from sa_allowance_hard_holiday ORDER BY sa_allowance_hard_holiday.is_status desc";
$m_query=mysql_query($query);
?>
				<table class="cssTable" border="1" style="width:100%">
					<thead>
						<tr>
							<th scope="col" style="width:10px"></th>
							<th scope="col" style="height:45px;"><?php echo $l_late;?></th>
							<th scope="col"><?php echo $l_half_dayoff;?></th>
							<th scope="col"><?php echo $l_all_dayoff;?></th>
							<th scope="col"><?php echo $l_allowance_hard;?></th>
							<th scope="col"><?php echo $l_sub_salary_day;?></th>
							<th scope="col"><?php echo $l_allowance_holiday;?></th>
							<th scope="col"><?php echo $l_Activestatus;?></th>
						</tr>
					</thead>
					<tbody>
						<?php 
							if(mysql_num_rows($m_query)>0){
								$i=0;
								while($row=mysql_fetch_array($m_query)){
								
									if($row[is_status]==1){
										?>
									<tr style="color:green;">
										<?php 
									}else{
									?>
									<tr>
									<?php }?>
									<td style="width:10px;" ><div style="text-align:center;"><input onclick="checkonly(this.id,document.nsa_f_allowance_hard_holiday.list);" type="checkbox" name="list" id="<?php echo 'checkcus'.$i?>" value="<?=$row[id]?>" /></div></td>
									<td ><?php echo $row[is_late]."(".$l_lan.")";?></td>
									<td><?php echo $row[is_half_dayoff]."(".$l_lan.")";?></td>
									<td ><?php echo $row[is_all_dayoff]."(".$l_lan.")";?></td>
									<td ><?php echo number_format($row[allowance_hard]);?></td>
									<td ><?php echo $row[sub_salary_day]."(".$l_ngay.")";?></td>
									<td ><?php echo number_format($row[allowance_holiday]);?></td>
									<td >
										<?php 
											if($row[is_status]==1){
												echo $l_active;
											}else{
												echo $l_status_saved;
											}
										?>
									</td>
									</tr>
								<?php 
									$i++;
								}
							}
						?>
					</tbody>
				</table>
				<div style="width:100px;align:center;">
					<input type="hidden" name="viewloi" id="viewloi" value="<?php echo $_SESSION['loi_allowance_hard_holiday'];?>" />
				</div>
				<?php mysql_close($connection);?>